import allure

from src.api.base_api import BaseApi


class ShopLink(BaseApi):
    def __init__(self, base_url):
        super().__init__(base_url)

    @allure.step("分类统计列表")
    def list(self, platform="dy", day_type=7):
        """
        url=https://ck-medium-api-test.cds8.cn/v1/class/list
        get

        """
        params = {
            "platform": platform,
            "day_type": day_type,
            "keyword": "",
            "p_keyword": "",
            "order_by": "",
            "sort": 2,
            "page": 1,
            "size": 20
        }

        json_res = self.send(method="get", path='class/list', params=params)
        return json_res

    @allure.step("添加分类")
    def create(self, name="test_api", platform="dy"):
        """
        url=https://ck-medium-api-test.cds8.cn/v1/class/add
        post
        """
        body = {
            "name": name,
            "platform": platform
        }
        json_res = self.send(method="post", path='class/add', json=body)
        return json_res

    @allure.step("更新分类")
    def update(self, id="", name="", is_del=""):
        """
        url=https://ck-medium-api-test.cds8.cn/v1/class/update
        post
        """
        body = {
            "id": id,
            "name": name,
            "is_del": is_del
        }
        json_res = self.send(method="post", path='class/update', json=body)
        return json_res


